/*
 * @Author: 黄达全
 * @Date: 2024-08-03 23:35:14
 * @LastEditTime: 2024-08-08 23:20:40
 */
import axios from "../index"
import type { ImageApi, ImageInsertVO, ApiResponse, ImageClassPageVO, ImageClassEntity, ImagePageVO } from "@/common/type"


export default {
    //                                         图片分类
    //新增图片分类
    async add(form) {
        return (await axios.post("/admin/image_class", form)).data as ApiResponse<ImageInsertVO>
    },
    // 删除图片分类
    async delete(id: number) {
        return (await axios.delete(`/admin/image_class/${id}`)).data as ApiResponse<null>
    },
    // 修改图片分类
    async update(form) {
        return (await axios.put("/admin/image_class", form)).data as ApiResponse<null>
    },
    // 分页获取图片分类
    async page(page, pageSize) {
        return (await axios.get(`/admin/image_class/${page}?limit=${pageSize}`)).data as ApiResponse<ImageClassPageVO>
    },
    // 获取图片分类
    async select() {
        return (await axios.get(`/admin/image_class`)).data as ApiResponse<ImageClassEntity[]>
    },

    //                                  图片图片    
    // 新增图片
    async addImageByCategory(requestbody, imageClassId) {
        return (await axios.post(`/admin/image/${imageClassId}`, requestbody)).data as ApiResponse<null>
    },
    // 删除图片
    async deleteImage(id: number, filename: string) {
        return (await axios.delete(`/admin/image/${id}`, {
            data: {
                filename
            }
        })).data as ApiResponse<null>
    },
    // 编辑图片
    async editImage(form) {
        return (await axios.put("/admin/image", form)).data as ApiResponse<null>
    },
    // 获取指定分类下的图片
    async getImageByCategoryByPage(id, page, limit) {
        return (await axios.get(`/admin/image/${id}`, {
            params: {
                page,
                limit
            }
        })).data as ApiResponse<ImagePageVO>
    },

} as ImageApi

export const imageApi = "/api/admin/image/upload"